package cn.dog.netty.controller;

import cn.dog.netty.model.User;
import cn.dog.netty.router.Controller;
import cn.dog.netty.router.RequestMapping;
import cn.dog.netty.util.GeneralResponse;
import cn.dog.netty.util.JsonUtil;
import io.netty.handler.codec.http.FullHttpRequest;
import lombok.extern.slf4j.Slf4j;

@Slf4j
@Controller
public class DemoController {

    @RequestMapping(uri = "/hello", method = "GET")
    public GeneralResponse hello() {
        return new GeneralResponse("hello");
    }

    @RequestMapping(uri = "/login",method = "POST")
    public GeneralResponse login(FullHttpRequest request) {
        User user = JsonUtil.fromJson(request, User.class);
        log.info("user name {}  password  {}",user.getUsername(),user.getPassword());
        return new GeneralResponse(user);
    }
}
